package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentHeroAround;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentHeroData;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentHeroGuide;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentHeroIntroduce;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentHeroPlay;
import liumengbaio.lolzhangyoubao.Activity.InFo.FreeHeroInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/8/30.
 */
public class HeroDetailsActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView herodetails, name, money, point;
    private ImageView favorite,icon;
    private Button btn_return, btn_share, merge;
    private Button btn_introduce, btn_data, btn_play, btn_guide, btn_around;
    private FrameLayout container;
    private android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
    private android.support.v4.app.FragmentTransaction transaction;
    private FragmentHeroIntroduce introduce;
    private FragmentHeroData data;
    private FragmentHeroPlay play;
    private FragmentHeroGuide guide;
    private FragmentHeroAround around;
    private int times = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_herodetails);
        initView();
        initData();
    }

    private void initView() {
        herodetails = (TextView) findViewById(R.id.tv_herodetails);
        name = (TextView) findViewById(R.id.tv_name);
        money = (TextView) findViewById(R.id.tv_money);
        point = (TextView) findViewById(R.id.tv_point);
        merge = (Button) findViewById(R.id.btn_merge);
        icon= (ImageView) findViewById(R.id.iv_icon);
        favorite = (ImageView) findViewById(R.id.iv_favorite);
        favorite.setOnClickListener(this);
        btn_return = (Button) findViewById(R.id.btn_herodetails_return);
        btn_return.setOnClickListener(this);
        btn_share = (Button) findViewById(R.id.btn_herodetails_share);

        btn_introduce = (Button) findViewById(R.id.btn_introduce);
        btn_data = (Button) findViewById(R.id.btn_data);
        btn_play = (Button) findViewById(R.id.btn_play);
        btn_guide = (Button) findViewById(R.id.btn_guide);
        btn_around = (Button) findViewById(R.id.btn_around);
        container = (FrameLayout) findViewById(R.id.heroframelayout);

    }

    private void initData() {

        FreeHeroInfo info = (FreeHeroInfo) getIntent().getSerializableExtra("hero");

        Picasso.with(HeroDetailsActivity.this).load(info.getPic_url()).into(icon);
        name.setText(info.getNickname()+"-"+info.getName());
        money.setText("金币 "+info.getMoney());
        point.setText("点券 "+info.getPoint());
        merge.setText(info.getFilter());




        introduce = FragmentHeroIntroduce.newInstants(info);
        data = FragmentHeroData.newInstants(info);
        play = FragmentHeroPlay.newInstants(info);
        guide = FragmentHeroGuide.newInstants(info);
        around = FragmentHeroAround.newInstants(info);
        transaction = fm.beginTransaction();
        transaction.add(R.id.heroframelayout, introduce,"introduce");
        transaction.add(R.id.heroframelayout, data,"data");
        transaction.add(R.id.heroframelayout, play,"play");
        transaction.add(R.id.heroframelayout, guide,"guide");
        transaction.add(R.id.heroframelayout, around,"around");
        transaction.show(introduce);
        transaction.hide(data);
        transaction.hide(play);
        transaction.hide(guide);
        transaction.hide(around);
        transaction.commit();
    }

    public void Introduce(View view) {
        herodetails.setText("英雄介绍");
        btn_share.setVisibility(View.GONE);
        btn_introduce.setBackgroundResource(R.drawable.tab_hero_intro_sel);
        btn_data.setBackgroundResource(R.drawable.tab_hero_data_nor);
        btn_play.setBackgroundResource(R.drawable.tab_hero_play_nor);
        btn_guide.setBackgroundResource(R.drawable.tab_hero_guide_nor);
        btn_around.setBackgroundResource(R.drawable.tab_hero_around_nor);
        FragmentTransaction introduce_fragment = fm.beginTransaction();
        introduce_fragment.show(introduce);
        introduce_fragment.hide(data);
        introduce_fragment.hide(play);
        introduce_fragment.hide(guide);
        introduce_fragment.hide(around);
        introduce_fragment.commit();

    }

    public void Data(View view) {
        herodetails.setText("英雄数据");
        btn_share.setVisibility(View.VISIBLE);
        btn_introduce.setBackgroundResource(R.drawable.tab_hero_intro_nor);
        btn_data.setBackgroundResource(R.drawable.tab_hero_data_sel);
        btn_play.setBackgroundResource(R.drawable.tab_hero_play_nor);
        btn_guide.setBackgroundResource(R.drawable.tab_hero_guide_nor);
        btn_around.setBackgroundResource(R.drawable.tab_hero_around_nor);
        FragmentTransaction data_fragment = fm.beginTransaction();
        data_fragment.show(data);
        data_fragment.hide(introduce);
        data_fragment.hide(play);
        data_fragment.hide(guide);
        data_fragment.hide(around);
        data_fragment.commit();
        favorite.setOnClickListener(this);
    }

    public void Play(View view) {
        herodetails.setText("英雄玩法");
        btn_share.setVisibility(View.GONE);
        btn_introduce.setBackgroundResource(R.drawable.tab_hero_intro_nor);
        btn_data.setBackgroundResource(R.drawable.tab_hero_data_nor);
        btn_play.setBackgroundResource(R.drawable.tab_hero_play_sel);
        btn_guide.setBackgroundResource(R.drawable.tab_hero_guide_nor);
        btn_around.setBackgroundResource(R.drawable.tab_hero_around_nor);
        FragmentTransaction play_fragment = fm.beginTransaction();
        play_fragment.show(play);
        play_fragment.hide(introduce);
        play_fragment.hide(data);
        play_fragment.hide(guide);
        play_fragment.hide(around);
        play_fragment.commit();

    }

    public void Guide(View view) {
        herodetails.setText("英雄攻略");
        btn_share.setVisibility(View.GONE);
        btn_introduce.setBackgroundResource(R.drawable.tab_hero_intro_nor);
        btn_data.setBackgroundResource(R.drawable.tab_hero_data_nor);
        btn_play.setBackgroundResource(R.drawable.tab_hero_play_nor);
        btn_guide.setBackgroundResource(R.drawable.tab_hero_guide_sel);
        btn_around.setBackgroundResource(R.drawable.tab_hero_around_nor);
        FragmentTransaction guide_fragment = fm.beginTransaction();
        guide_fragment.show(guide);
        guide_fragment.hide(introduce);
        guide_fragment.hide(data);
        guide_fragment.hide(play);
        guide_fragment.hide(around);
        guide_fragment.commit();
    }

    public void Around(View view) {
        herodetails.setText("英雄周边");
        btn_share.setVisibility(View.GONE);
        btn_introduce.setBackgroundResource(R.drawable.tab_hero_intro_nor);
        btn_data.setBackgroundResource(R.drawable.tab_hero_data_nor);
        btn_play.setBackgroundResource(R.drawable.tab_hero_play_nor);
        btn_guide.setBackgroundResource(R.drawable.tab_hero_guide_nor);
        btn_around.setBackgroundResource(R.drawable.tab_hero_around_sel);
        FragmentTransaction around_fragment = fm.beginTransaction();
        around_fragment.show(around);
        around_fragment.hide(introduce);
        around_fragment.hide(data);
        around_fragment.hide(play);
        around_fragment.hide(guide);
        around_fragment.commit();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_herodetails_return:
                finish();
                break;
            case R.id.iv_favorite:
                if (times == 0) {
                    favorite.setBackgroundResource(R.drawable.hero_fav);
                    Toast.makeText(this, "收藏成功", Toast.LENGTH_SHORT).show();
                    times = 1;
                } else {
                    favorite.setBackgroundResource(R.drawable.hero_defav);
                    Toast.makeText(this, "取消收藏成功", Toast.LENGTH_SHORT).show();
                    times = 0;
                }
                break;

        }
    }
}
